﻿<?php
	require("includes/php/requirements.php");
	$action = fetch("action");
	if ($action!="" && array_key_exists(strtolower($action), $handlers)) {
		$handler = $handlers[$action];
		if ($handler["requireAuthentication"] && !($IsAuthenticated)) {
			?>
			<script language="javascript" type="text/javascript">
				SetViewKey("Login");
			</script>
			<?php
		} else {
			$notification = false;
			$callback = false;
			$handleResult = false;
			@include($handler["path"]);
			$resultView = $handleResult? $handler["succeedView"] : $handler["failView"];
			?>
			<script language="javascript" type="text/javascript">
				<?php $callback = $callback? ' , function() { '.$callback . '}' : ''; ?>
				SetViewKey('<?php echo ucFirst(strtolower($resultView)); ?>'<?php echo $callback; ?>);
				<?php if ($notification) { ?>
					Notify('<?php echo $notification; ?>');
				<?php } ?>
			</script>
			<?php
		}
	} else {
		?>
		<script language="javascript" type="text/javascript">
			SetViewKey("Main");
		</script>
		<?php
	}
?>